import { Injectable, Logger } from "@nestjs/common";
import { ShareContentDto, ShareRecordDto } from "./share.dto";
import { ShareContentEntity } from "./share-content.entity";
import { ShareRecordsEntity } from "./share-records.entity";
import { Repository } from "typeorm";
import { InjectRepository } from "@nestjs/typeorm";

@Injectable()
export class ShareService {
	private readonly logger = new Logger(ShareService.name);

	@InjectRepository(ShareContentEntity)
	private readonly shareContentEntity: Repository<ShareContentEntity>

	@InjectRepository(ShareRecordsEntity)
	private readonly shareRecord: Repository<ShareRecordsEntity>

	/**
	 * 记录用户分享出去的内容
	 * @param  dto
	 * @returns
	 */
	async recordShare(dto: ShareContentDto, uid: number) {
		return await this.shareContentEntity.save({ ...dto, user: { id: uid } as any });
	}

	/**
	 * 记录用户点击分享链接进入的记录
	 * @param  dto
	 * @returns
	 */
	async recordShareEnter(dto: ShareRecordDto) {
		return await this.shareRecord.save(dto);
	}
}